package com.example.academic_affairs_system.mapper.provider;

import org.apache.ibatis.jdbc.SQL;

/**
 * 班级课表
 *
 * @author hjx
 * @since 2023/02/05 1:18 PM
 */
public class AasClassCoursesProvider {
  public String getClassVOByCoursesId() {
    return new SQL() {
      {
        SELECT(
                "ac.id as classId",
                "ac.name",
                "ac.`type`",
                "ac.`desc`",
                "round(avg(`asc`.grades), 2) as aveSource")
            .FROM("aas_class_courses acc")
            .LEFT_OUTER_JOIN("aas_class ac on ac.id = acc.class_id")
            .LEFT_OUTER_JOIN("aas_class_student acs on acs.class_id = ac.id")
            .LEFT_OUTER_JOIN(
                "aas_student_courses `asc` on `asc`.student_id = acs.student_id and `asc`.courses_id = acc.courses_id ")
            .WHERE("acc.courses_id = #{coursesId} and ac.enabled = 1")
            .GROUP_BY("acc.class_id");
      }
    }.toString();
  }
}
